<template>
	<view>
		<!-- 搜索 -->
		<!-- <view class="searchViewi">
			<view class="searchView">
				<view class="searchViewLeft">
					<u-icon name="search" size="30" color="#999999"></u-icon>
				</view>
				<view class="searchViewRight">
					<u-input placeholder="姓名/职务" inputAlign="left" :border="false" v-model="jiebieQuery.userName">
					</u-input>
				</view>
			</view>
		</view> -->

		<view class="">
			<category :categoryList="categoryList" :subCategoryList="subCategoryList" @tjly="tjly"
				@categoryMainClick="categoryMainClick" @categorySubClick="categorySubClick"></category>
		</view>
	</view>
</template>

<script>
	import category from "@/pagesB/components/qiyue-category/qiyue-category.vue"
	export default {
		data() {
			return {
				id: '',
				llzId:'',
				indexNum: 0,
				value: '',
				categoryList: [],
				subCategoryList: [],
				jiebieQuery: {
    				"dbzjId":"",	//代表之家主键id
					"llzId":"",	//联络站主键id
    				"userName":"",		//姓名
    				"userPosition":""	//职务
				}
			}
		},
		components: {
			category
		},
		computed: {
			jiebieQueryUserName() {
				return this.jiebieQuery.userName
			}
		},
		onLoad(e) {
			if (e.id) {
				this.id = e.id
				this.getDept()
			}
		},
		watch: {
			jiebieQueryUserName(e,v){
				this.isSearch(e)
			}
		},
		mounted() {
		},
		methods: {
			getDept() {
				let that = this
				this.$request(
					'/system/sys-dept/getChildren', {
						parentId:that.id,
						rpcFlag:1
					}, {
						load: true
					}
				).then(res => {
					if (res.code == 200) {
							that.categoryList = []
							res.data.records.map((item, index) => {
								that.categoryList.push({
									"name": item.deptNameRpc,
									"dictValue": item.id,
									"data": item,
									"subCategoryList": []
								})
							})
							that.getDistItem(res.data.records[0].dictValue, 0,res.data.records[0])
						
					}
				});
			},
			tjly(e, v) {
				
				// //委员id
				// if (option && option.representiveId) {
				// 	this.form.representiveId = option.representiveId;
				// }
				
				// //委员名字
				// if (option && option.userName) {
				// 	this.form.userName = option.userName;
				// }
				
				// //联络站名字
				// if (option && option.stationName) {
				// 	this.form.stationName = option.stationName;
				// }
				
				// if (option && option.stationId) {
				// 	this.form.stationId = option.stationId;
				// } 
				console.log("eee",e)
				uni.navigateTo({
					url: '../foem/foem?id=' + '' + '&representiveId=' + e.dbUserId + '&userName=' + e.dbUserName + '&stationName=' + e.staName + '&stationId=' + e.staStaDeptId
				})
			},
			getDist(e) {
				let that = this
				this.$request(
					'/system/sys-dict/dictList', {
						sysDict: {
							dictType: e
						},
						clientCode: '3707'
					}, {
						load: true
					}
				).then(res => {
					if (res.code == 200) {
						that.categoryList = []
						res.data.records.map((item, index) => {
							that.categoryList.push({
								"name": item.dictName,
								"dictValue": item.dictValue,
								"data": item,
								"subCategoryList": []
							})
						})

						that.getDistItem(res.data.records[0].dictValue, 0,res.data.records[0])
					}
				});
			},
			getDistItem(e, v , t) {
				let that = this
				let a = JSON.parse(JSON.stringify(that.jiebieQuery))
				a.dbzjId = that.id
				this.llzId = t.id
				a.llzId = t.id
				a.rpcFlag = 1
				this.$request(
					'/minqingzhitong/msManageDept/getStaUserList', a, {
						load: true
					}
				).then(res => {
					if (res.code == 200) {
						this.subCategoryList = res.data.result;
						this.$forceUpdate()

					}
				});
			},
			isSearch(e){
				let that = this
				let a = JSON.parse(JSON.stringify(that.jiebieQuery))
				a.dbzjId = that.id
				a.llzId = this.llzId
				a.userName = e
				this.$request(
					'/minqingzhitong/msManageDept/getStaUserList', a, {
						load: true
					}
				).then(res => {
					if (res.code == 200) {
						
						this.subCategoryList = res.data.result;
						this.$forceUpdate()
				
					}
				});
			},
			categoryMainClick(e, v) {
				
				this.indexNum = v
				this.getDistItem(e.data.dictValue, v,e.data)
				// this.subCategoryList = category.subCategoryList;
			},
			categorySubClick(category) {
				console.log(category);
			}
		}
	}
</script>

<style lang="less">
	.searchViewi {
		padding: 20upx;
		border-bottom: 1upx solid #f5f7fa;

		.searchView {
			display: flex;
			align-items: center;
			padding: 10upx 15upx;
			border-radius: 20upx;
			background-color: #F6F7F8;

			.searchViewLeft {}

			.searchViewRight {
				padding-left: 20upx;
			}
		}
	}
</style>
